package com.itheima.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.dao.CheckitemDao;
import com.itheima.domain.CheckgroupCheckitem;
import com.itheima.domain.Checkitem;
import com.itheima.service.CheckgroupCheckitemService;
import com.itheima.service.CheckihemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class CheckitemServiceImpl extends ServiceImpl<CheckitemDao, Checkitem> implements CheckihemService {
    @Autowired
    private CheckgroupCheckitemService checkgroupCheckitemService;

    /**
     * 根据id进行多表删除
     * @param id
     */
    @Override
    @Transactional
    public void removeWithAnother(Integer id){

        //在t_checkgroup_checkitem表中根据checkitem_id进行查询
        LambdaQueryWrapper<CheckgroupCheckitem> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(CheckgroupCheckitem::getCheckitemId,id);
        List<CheckgroupCheckitem> list = checkgroupCheckitemService.list(queryWrapper);
        if(list!=null){
            checkgroupCheckitemService.remove(queryWrapper);
        }

        //在t_checkitem表中根据id进行删除
        this.removeById(id);
    }
    @Autowired
    private  CheckitemDao checkitemDao;


    @Override
    public void edit(Checkitem checkitem) {
        checkitemDao.edit(checkitem);
    }

    public Checkitem findById(Integer id) {
        return checkitemDao.findById(id);
    }

}
